#include <stdio.h>

int main()
{
#if 0
    FILE *f = fopen("./telephone.txt", "r");
    if (f == NULL)
    {
        printf("文件打开失败!\n");
        return -1;
    }
    char name[20] = {0};
    char tel[20] = {0};
    while(1)
    {
        // 返回值代表读取的字节数，为-1代表读取结束
        if(fscanf(f, "%s %s\n", name, tel) < 0)
        {
            break;
        }
        printf("name : %s tel : %s\n", name, tel);
    }
    fclose(f);
#endif

#if 1
    FILE *f = fopen("./telephone.txt", "w");
    if (f == NULL)
    {
        printf("文件打开失败!\n");
        return -1;
    }
    char name[20] = "zhangsan";
    char tel[20] = "1234567";
    fprintf(f, "name = %s tel = %s\n", name, tel);
    fclose(f);
#endif
    
    return 0;
}